package nc.ui.so.syncest.action;

import java.awt.Container;
import java.awt.event.ActionEvent;

import nc.bs.framework.common.NCLocator;
import nc.ui.pub.beans.UIDialog;
import nc.ui.pubapp.uif2app.query2.DefaultQueryConditionDLG;
import nc.ui.uif2.NCAction;
import nc.ui.uif2.model.AbstractUIAppModel;
import nc.vo.pubapp.AppContext;
import nc.vo.querytemplate.QSMode;
import nc.vo.querytemplate.TemplateInfo;
import nc.vo.so.syncest.AggEasSyncestVO;

public abstract class AbsEstPubAction extends NCAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private AbstractUIAppModel model = null;
	
	@Override
	public void doAction(ActionEvent event) throws Exception {
		DefaultQueryConditionDLG dqcd = getDefaultQueryConditionDLG("40060655", getNodeKey());
		
		if (dqcd.showModal() == UIDialog.ID_OK) {
			AggEasSyncestVO[] results = NCLocator.getInstance().lookup(nc.itf.so.ISyncestMaintain.class).queryEstData(this.getClass().getName(), dqcd.getQueryScheme().getWhereSQLOnly());
			
			model.initModel(results);
			
		}
	}
	
	protected String getNodeKey() {
		return "ys";
	}

	@Override
	protected boolean isActionEnable() {
		return super.isActionEnable();
	}
	
	public DefaultQueryConditionDLG getDefaultQueryConditionDLG(String funNode,
			String nodeKey) {
		TemplateInfo ti = new TemplateInfo();
		ti.setDataPowerForceSwitchOn(true);
		ti.setFunNode(funNode);

		ti.setMultiCorpRef(true);
		ti.setSealedDataShow(true);
		ti.setShowTableName(true);
		ti.setOrgType("1");

		String pk_group = AppContext.getInstance().getPkGroup();
//		String pk_org = card.getModel().getContext().getPk_org();

		ti.setPk_Org(pk_group);
		ti.setQSMode(QSMode.USER);
		ti.setQueryType(-1);
		ti.setNodekey(nodeKey);
//		ti.setTemplateId(templetID);
		String userId = AppContext.getInstance().getPkUser();
		ti.setUserid(userId);

		DefaultQueryConditionDLG dqcd = new DefaultQueryConditionDLG(
				new Container(), ti);

//		dqcd.setDefaultValue("pk_org", pk_org);
//		dqcd.setDefaultValue("pk_group", pk_group);

		return dqcd;
	}

	public AbstractUIAppModel getModel() {
		return model;
	}

	public void setModel(AbstractUIAppModel model) {
		this.model = model;
		this.model.addAppEventListener(this);
	}

}
